package com.gitee.theskyzero.framework.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

@Component
@Aspect
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class SimpleAspect {


    @Pointcut("execution(* com.gitee.theskyzero..*(..))")
    public void pointCutExec() {
    }

    @Before(value = "pointCutExec() && @annotation(log)")
    public void beforePointCut(Log log) {
        System.out.println(log.desc());
    }

    @Around("@annotation(log)")
    public Object aroundPointCut(ProceedingJoinPoint joinPoint, Log log) {
        try {
            return joinPoint.proceed();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        } finally {
            System.out.println(" around log: desc=" + log.desc());
        }
    }
}
